﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using MyProj.MVCProj3.IDAL;
using MyProj.MVCProj3.Model;

namespace MyProj.MVCProj3.DAL
{
    /// <summary>
    /// 本类包含所有的DAL仓库，是一个partial类
    /// </summary>
    partial class DbSession : IDAL.IDbSession
    {
        //t4模版自动生成各个仓库的interface;
        //IBaseRepository<MyProj.MVCProj3.Model.UserInfo> UserInfo = new UserInfoRepository();
        private IBaseRepository<UserInfo> _UserInfo;
        public IBaseRepository<UserInfo> UserInfo
        {
            get
            {
                if (_UserInfo == null)
                {
                    _UserInfo = new UserInfoRepository();

                } return _UserInfo;
            }
            set
            {
                _UserInfo = value;
            }
        }
        ObjectContext DbContext = MyProj.MVCProj3.DAL.DbContextFactory.GetCurrentDbContext();

        public int ExcuteSql(string sql, params ObjectParameter[] parameters)
        {
            return DbContext.ExecuteFunction(sql, parameters);
        }

        /// <summary>
        /// unit工作模式，进行统一的保存操作
        /// </summary>
        /// <returns></returns>
        public int SaveChanges()
        {
            int num = DbContext.SaveChanges();

            return num;
        }
    }
}
